import { http } from '@/utils/http';
import { SilentInfo } from '@/typings';
import type { OpenIdItem, Phone, Student } from './index.d';

export { OpenIdItem, Phone, Student };

/** 退出登录 */
export const userLogout = () => {
	return http({
		url: `/api/auth/logout`,
		method: 'GET',
	});
};

/** 退出班级 */
export const userExitClass = (student_id: number) => {
	return http({
		url: `/api/student/student_quit_class`,
		method: 'POST',
		data: { student_id },
	});
};

/** 获取用户openid */
export const getUserOpenid = (code: string) => {
	return http<OpenIdItem>({
		url: `/api/auth/wx_verify`,
		method: 'POST',
		data: { code },
	});
};

/** 获取用户手机号 */
export const getUserPhone = (data: Phone.Params) => {
	return http<Phone.Data>({
		url: `/api/auth/login_wx`,
		method: 'POST',
		data,
	});
};

/** 获取用户默认登录的学生账号 */
export const getDefaultUserInfo = () => {
	return http<Student.DefaultUserInfo>({
		url: `/api/student/student_get_default`,
		method: 'POST',
	});
};

/** 奢姿用户默认登录的学生账号 */
export const setDefaultUserInfo = (id: number) => {
	return http<Student.DefaultUserInfo>({
		url: `/api/student/student_set_default`,
		method: 'POST',
		data: id ? { student_id: id } : {},
	});
};

/** 获取所有学生列表 */
export const getStudentList = () => {
	return http<Student.StudentList[]>({
		url: `/api/student/student_list`,
		method: 'POST',
	});
};

/** 用户添加学生账号 */
export const addStudentInfo = (data: Student.AddParams) => {
	return http({
		url: `/api/student/add_user_student`,
		method: 'POST',
		data,
	});
};

/** 用户编辑学生账号 */
export const editStudentInfo = (data: Student.AddParams) => {
	return http({
		url: `/api/student/edit_student_info`,
		method: 'POST',
		data,
	});
};

/** 用户删除学生账号 */
export const delStudentInfo = (data: Student.DeleteParams) => {
	return http({
		url: `/api/student/del_user_student`,
		method: 'POST',
		data,
	});
};

/** 用户编辑学生头像 */
export const editStudentAvatar = (data: Student.EditAvatarParams) => {
	return http<Student.EditAvatarData>({
		url: `/api/student/upload_student_avatar`,
		method: 'POST',
		data,
	});
};

/** 获取学生信息及阅读统计数据 */
export const getMyCenterInfo = (data: Student.CenterInfoParams) => {
	return http<Student.CenterInfoData>({
		url: `/api/student/get_student_info`,
		method: 'POST',
		data,
	});
};

/** 静默登录获取token - userInfo */
export const getSilenterInfo = (code: string) => {
	return http<SilentInfo>({
		url: `/api/auth/login_silent_wx`,
		method: 'POST',
		data: { code },
	});
};

/** 获取阅读记录统计 */
export const getReadStatistics = (student_id: number) => {
	return http<Student.ReadRecordStatistics[]>({
		url: `/api/bookreadrecord/book_read_statistics`,
		method: 'POST',
		data: { student_id },
	});
};

/** 获取阅读记录列表 */
export const getReadRecordList = (data: Student.ReadRecordParams) => {
	return http<Student.ReadRecordData[]>({
		url: `/api/bookreadrecord/book_read_list`,
		method: 'POST',
		data,
	});
};

/** 获取测练记录列表 */
export const getExamRecordList = (data: Student.ExamRecordParams) => {
	return http<Student.ReadRecordData[]>({
		url: `/api/student/exam_record_list`,
		method: 'POST',
		data,
	});
};

/** 获取共读记录列表 */
export const getPlanRecordList = (query: Student.PlanRecordParams) => {
	return http<Student.PlanRecordData>({
		url: `/api/plan/my`,
		method: 'GET',
		query,
	});
};

/** 领取书本积分 */
export const getReceivePoint = (data: Student.PointParams) => {
	return http({
		url: `/api/plan/collect_book_integral`,
		method: 'POST',
		data,
	});
};

/** 领取书本积分 */
export const getPlanReceive = (data: Student.PlanPointParams) => {
	return http({
		url: `/api/plan/collect_plan_integral`,
		method: 'POST',
		data,
	});
};
